<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function validate(){
            //if(!/^\w{6}$/.test($('t1').value)){
            if($('t1').length > 6){
                console.log('用户名错误')
                return false;
            }
            if(!/^\w{6}$/.test($('p1').value)){
                console.log('密码错误')
                return false;
            }
            //..........
            return true;
        }

        function $(id){
            return document.getElementById(id);
        }
    </script>

</head>

<body>
    <!--如果validate()返回false 表单不提交-->
    <form action="/add" onsubmit="return validate()">
        <input id="t1"/><br/>
        <input type="password" id="p1"/>
        <input type="submit"/>
    </form>
</body>
</html>

